<!-- index.html -->
<!DOCTYPE html>
<html>
<body>
<button type="button" onclick="callArkTS()">Click Me!</button>
<p id="demo"></p>
<script>
  // 检查当前是否有打开的图片预览
  function checkImageViewerAndCallNative() {
    let observer = new MutationObserver(mutations => {
      if (mutations?.length) {
        const mutation = mutations[0]
        const currentValue = mutation.target.getAttribute(mutation.attributeName)
        let hasOpenViewer = currentValue === 'van-overflow-hidden'
        nativeJSCallBack.print(hasOpenViewer);
        // 如果存在打开的预览，调用原生方法
        if (hasOpenViewer) {
        nativeJSCallBack.sourcePreview(true);
        }else{
        nativeJSCallBack.sourcePreview(false);
        }
      }
    })
    observer.observe(document.body, {
      attributes: true,
      attributeFilter: ['class'], // 明确指定只监听此属性
      attributeOldValue: true, // 记录旧值用于比对
      subtree: false
    })
  }
</script>
</body>
</html>